<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>推荐管理</title>
<meta name="decorator" content="default"/>
<script type="text/javascript">
	//url
	var listUrl = '${ctx}/cms/recommen/';
	var cardUrl = '${ctx}/cms/recommen/form';
	var formGroupUrl = '${ctx}/cms/recommen/formGroup';
	var sortUrl = "${ctx}/cms/recommen/updateSort";
	jQuery(document).ready(function() {
		
	});
	function page(n, s) {
		$("#pageNo").val(n);
		$("#pageSize").val(s);
		$("#searchForm").submit();
		return false;
	}
	
	function add(displayType) { //新增记录
		var url = null;
		if(displayType !=null){ //轮播图
			url = formGroupUrl;
		
		}else{ //其他
			url = cardUrl ;
		}
		url = addUrlParam(url,'opt','add');
		url = addUrlParam(url,'ispublish.id',0);
		url = addUrlParam(url,'displaytype.id',displayType);
		url = addUrlParam(url,'rescomtype.id',0);
		parent.freshTabs(jQuery(window.parent.document).find('[link="iframeContent2"]'), url);
	}
	
	function edit(obj, isEdit) { //修改记录
		var curentTr = null;
		if (obj != null) {
			curentTr = jQuery(obj).parents('tr')[0];
		} else {
			var table = jQuery("#contentTable");
			var checkboxs = jQuery('input[attrname="sort"]:checked', table);
			if (checkboxs.length == 0) {
				alertx("请选择一行数据！");return;
			} else if (checkboxs.length > 1) {
				alertx("只能选择一行数据！");return;
			}
			curentTr = jQuery(checkboxs[0]).parents('tr')[0];
		}
		var id = jQuery('[attrname="id"]', curentTr).val();
		var displayType = jQuery('[attrname="displaytype.id"]', curentTr).val();
		if (id != null || id != '') {
			var url = null;
			var opt = (isEdit==true || isEdit == null) ? 'edit' : 'other';
			if(displayType !=null){ //轮播图
				url = formGroupUrl;
			}else{ //其他
				url = cardUrl ;
			}
			url = addUrlParam(url,'opt',opt);
			url = addUrlParam(url,'id',id);
			url = addUrlParam(url,'displaytype.id',displayType);
			parent.freshTabs(jQuery(window.parent.document).find('[link="iframeContent2"]'), url);
		}
	}
	
	function detail(obj) { //查看记录详情
		edit(obj, false);
	}
	
	function del(obj) { //删除记录
		if (obj != null) { //单个删除
			var curentTr = jQuery(obj).parents('tr')[0];
			var id = jQuery('[attrname="id"]', curentTr).val();
			var url = listUrl + 'delete?id=' + id;
			confirmx('确认要删除该赛事视频吗？', function() {
				window.location.href = url;
			});
		} else { //批量删除
			var table = jQuery("#contentTable");
			var checkboxs = jQuery('input[attrname="sort"]:checked', table);
			if (checkboxs.length == 0) {
				alertx("请选择至少一行数据！");
				return;
			}
			var ids = [];
			for (var i = 0; i < checkboxs.length; i++) {
				var curentTr = jQuery(checkboxs[i]).parents('tr')[0];
				var id = jQuery('[attrname="id"]', curentTr).val();
				ids.push(id);
			}
			var url = listUrl + 'batchDelete?ids=' + ids.join();
			confirmx('确认要删除所选赛事视频吗？', function() {
				window.location.href = url;
			});
		}
	}
	
	function submitData(){ //提交表单
		var formObj = null;
		if(obj == null){
			formObj = jQuery("#searchForm")[0];
		}else{
			formObj = jQuery(obj).parents('form')[0];
		}
		if(formObj!=null){
			formObj.submit();
		}
	}
	
	function resetForm(obj) { //重置查询条件
		var formObj = null;
		if(obj == null){
			formObj = jQuery("#searchForm")[0];
		}else{
			formObj = jQuery(obj).parents('form')[0];
		}
		if (jQuery(formObj)[0] != null) {
			jQuery(formObj)[0].reset();
		}
	}
	
	function clearForm(obj){ //清空查询条件
		var formObj = null;
		if(obj == null){
			formObj = jQuery("#searchForm")[0];
		}else{
			formObj = jQuery(obj).parents('form')[0];
		}
		if (jQuery(formObj)[0] != null) {
			jQuery(formObj).find(':input').each(function(){ 
	            switch(this.type){  
	                case 'passsword':  
	                case 'select-multiple':  
	                case 'select-one':  
	                case 'text':  
	                case 'textarea':  
	                    jQuery(this).val('');  
	                    break;  
	                case 'checkbox':  
	                case 'radio':  
	                    this.checked = false;  
	            }  
	        });     
		}
	}
	
	function updateSort() {
		loading('正在提交，请稍等...');
    	$("#listForm").attr("action",sortUrl );
    	$("#listForm").submit();
	}
	
	function selectRecommen(){
		var dialogOpts = { 
				width : 500,
				height: 300,
				modal: false,
				buttons: {       
					"Ok": function() {
						var showType = jQuery('#addForm').find('[name="displaytype.id"]').val();
						add(showType);
						$( this ).dialog( "close" );
					} , 
					"Cancel": function() {
						$( this ).dialog( "close" );
					}    
				} 
		};
		jQuery( "#dialog" ).dialog(dialogOpts);
	}
	
	//增加分组类型	
	function addGroup(showType){
		var url = formGroupUrl + '?opt=add&grouptype.id=1&displaytype='+showType+'&ispublish='+0;
		parent.freshTabs(jQuery(window.parent.document).find('[link="iframeContent2"]'), url);
	}
</script>
<style type="text/css">
.tableHead th, td {
	text-align: center;
}
</style>
</head>
<body>
	<form:form id="searchForm" modelAttribute="recommen" action="${ctx}/cms/recommen/" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<ul class="ul-form">
			<li><label>编码：</label>
				<form:input path="code" htmlEscape="false" maxlength="50" class="input-medium"/>
			</li>
			<li><label>名称：</label>
				<form:input path="name" htmlEscape="false" maxlength="100" class="input-medium"/>
			</li>
			<li><label>推荐类型：</label>
				<form:select path="rescomtype.id" class="input-medium">
					<form:option value="" label="--请选择--"/>
					<form:options items="${fns:getDictList('rescomtype')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</li>
			<li><label>显示类型：</label>
				<form:select path="displaytype.id" class="input-medium">
					<form:option value="" label="--请选择--"/>
					<form:options items="${fns:getDictList('displaytype')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</li>
			<li><label>所属栏目：</label>
				<sys:treeselect id="category" name="category.id" value="${recommen.category.id}" labelName="category.name" labelValue="${fns:getCategory(recommen.category.id).name}"
					title="所属栏目" url="/cms/category/treeData" cssClass="input-small" allowClear="true" notAllowSelectParent="true"/>
			</li>
			<li class="btns">
				<input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>
				<input id="btnReset" class="btn " type="reset" value="重置" onclick="resetForm(this)"/>
				<input id="btnClear" class="btn " type="button" value="清除" onclick="clearForm(this)"/>
			</li>
			<li class="clearfix"></li>
		</ul>
	</form:form>
	<sys:message content="${message}"/>
	<div class="" style="margin-bottom: 3px;">
		<shiro:hasPermission name="cms:recommen:edit">
			<input id="btnAdd" class="btn btn-primary" type="button" value="新 增" onclick="selectRecommen()"/>&nbsp;
			<input id="btnAddGroup1" class="btn btn-primary" type="button" value="新增轮播图" onclick="addGroup('1')"/>&nbsp;
			<input id="btnEdit" class="btn btn-primary" type="button" value="修 改" onclick="edit()"/>&nbsp;
			<input id="btnDel" class="btn btn-primary" type="button" value="删 除" onclick="del()"/>&nbsp;
			<input id="btnSort" class="btn " type="button" value="保存排序" onclick="updateSort()"/>
		</shiro:hasPermission>
		<shiro:hasPermission name="cms:recommen:view">
			<input id="btnDetail" class="btn " type="button" value="查 看" onclick="detail()"/>&nbsp;
		</shiro:hasPermission>	
	</div>
	<form id="listForm" method="post">
	<table id="contentTable" class="table table-striped table-bordered table-condensed table-hover">
		<thead>
			<tr class="tableHead">
				<th style="text-align:center;" onclick="toggleCheckBox('checkboxName',this)">
		  			<input type="checkbox" checkboxName="sort" name="table_form_checkbox_all" value="">
		  		</th>
		  		<th style="text-align:center;">序号</th>
				<!-- <th>编码</th> -->
				<th>推荐类型</th>
				<th>标题</th>
				<th>显示类型</th>
				<th>所属栏目</th>
				<th>顺序</th>
				<th>描述</th>
				<th>更新时间</th>
				<th>发布状态</th>
				<shiro:hasPermission name="cms:recommen:edit"><th>操作</th></shiro:hasPermission>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="recommen" varStatus="status">
			<tr>
				<td style="text-align:center;" >
					<input type="checkbox" name="sort1" attrname="sort" value="">
					<input type="hidden" attrname="id" value="${recommen.id}"/>
					<input type="hidden" attrname="displaytype.id" value="${recommen.displaytype.id}"/>
					<input type="hidden" attrname="code" value="${recommen.code}"/>
				</td>
				<td style="text-align:center;">
					<span attrname="number">${ status.index + 1}</span>
				</td>
				<%-- <td>
					${recommen.code}
				</td> --%>
				<td><a href="javascript:void(0);" onclick="detail(this)">
					${fns:getDictByTypeValue(recommen.rescomtype.id,'rescomtype').label}
					</a>
				</td>
				<td>
					${recommen.name}
				</td>
				<td>
					${fns:getDictByTypeValue(recommen.displaytype.id,'displaytype').label}
				</td>
				<td>
					${fns:getCategory(recommen.category.id).name}
				</td>
				<td>
					<input type="hidden" name="ids" value="${recommen.id}" maxlength="50" class="required" style="width:50px;"/>
					<input type="text" name="sorts" value="${recommen.sort}" maxlength="50" class="required" style="width:50px;"/>
				</td>
				<td>
					${recommen.remarks}
				</td>
				<td>
					<fmt:formatDate value="${recommen.updateDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
				</td>
				<td>
					${fns:getDictByTypeValue(recommen.ispublish.id,'publishstatus').label}
				</td>
				<shiro:hasPermission name="cms:recommen:edit"><td>
					<a href="javascript:void(0);" onclick="edit(this)">修改</a>
					<a href="javascript:void(0);" onclick="del(this)">删除</a>
				</td></shiro:hasPermission>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
	</form>
	
	<div id="dialog" title="选择推荐类型" style="display: none;">
		<form:form id="addForm" modelAttribute="recommen" action="${ctx}/cms/recommen/" method="post" class="breadcrumb form-search">
		<div class="control-group" style="height: 140px;">
			<label class="control-label">显示类型：</label>
			<div class="controls">
				<form:select path="displaytype.id" class="input-xlarge">
					<form:options items="${fns:getDictList('displaytype')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</div>
			
		</div>
		</form:form>
	</div>
	
</body>
</html>